<?php
/**
 * Created by PhpStorm.
 * User: yzh
 * Date: 2019/5/14
 * Time: 14:01
 */

namespace app\enterprise\service;


class Poster
{
    public $url = '';
    function __construct()
    {
        $this->url = config('setting.base_url');
    }

    /**
     *获取素材列表
     * @param $token
     * @return |null
     */
    public function getMaterial($token){
        $url = $this->url."/poster/category";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     *更具分类获取素材
     * @param $token
     * @return |null
     */
    public function getMaterialByClass($token,$class,$size,$page){
        $url = $this->url."/poster/list/";
        $params=['class'=>$class,'page'=>$page,'size'=>$size];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     *每日推荐海报
     * @param $token
     * @return |null
     */
    public function getRecommendPoster($token){
        $url = $this->url."/poster/recommend";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取二维码
     * @param $token
     * @param $m_id
     * @param $style
     * @param $path
     * @param $words
     * @return |null
     */
    public function getQRCode($token,$m_id,$style,$path,$words){
        $url = $this->url."/poster/qrcode/";
        $params=['m_id'=>$m_id,'style'=>$style,'path'=>$path,'words'=>$words];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 添加海报
     * @param $token
     * @param $id
     * @param $poster_id
     * @return |null
     */
    public function addPoster($token,$id,$poster_id){
        $url = $this->url."/poster/add";
        $params=['id'=>$id,'poster_id'=>$poster_id,];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取海报列表
     * @param $token
     * @param $size
     * @param $page
     * @return |null
     */
    public function getPosterList($token,$size,$page){
        $url = $this->url."/poster/user";
        $params=['size'=>$size,'page'=>$page,];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     *每日推荐海报
     * @param $token
     * @return |null
     */
    public function getAllUser($token){
        $url = $this->url."/poster/all";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取用户列表
     * @param $id
     * @return |null
     */
    public function getUserList($id,$token){
        $url = $this->url."/poster/userinfo/".$id;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }




}